<?php


namespace App\Http\Requests\Api;


use App\Exceptions\SysException;
use App\Facade\AppContext;
use App\Http\Requests\BaseFormRequest;
use App\Models\Job\Invite;
use Illuminate\Validation\Rule;

class InviteAuditRequest extends BaseFormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->get('id', 0);
        $invite = Invite::find($id);
        if (empty($invite)) {
            throw new SysException(__('common.tips.data_does_not_exist'));
        }
        if ($invite['direction'] == 1) {
            //学生
            if ($invite['student_id'] != AppContext::userId()) {
                throw new SysException(__('common.tips.data_error'));
            }
        } else {
            //企业员工
            if ($invite['staff_id'] != AppContext::userId()) {
                throw new SysException(__('common.tips.data_error'));
            }
            $status = $this->get('status', 2);
            if ($status == 2)
                return [
                    'date' => ['required'],
                    'time' => ['required']
                ];
        }

        return [
            'status' => ['required', Rule::in([2, 3])],
        ];
    }


    public function messages()
    {
        return __('job.invite.validation');
    }
}
